package com.moyq5.mvc.maker.test.bean.entity;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;

import com.moyq5.mvc.maker.test.bean.embed.TraChannelMerchBindId;

/**
 * 平台商户与渠道商户关联（分配）关系
 * @author Moyq5
 * @date 2018年12月3日
 */
@Entity
@Table(name = "tra_channel_merch_bind")
@DynamicUpdate
public class TraChannelMerchBind implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	/**
	 * 主键ID
	 */
	@EmbeddedId
	@AttributeOverrides({
			@AttributeOverride(name = "channelMerchId", column = @Column(name = "channel_merch_id", nullable = false, precision = 15, scale = 0)),
			@AttributeOverride(name = "merchId", column = @Column(name = "merch_id", nullable = false, precision = 15, scale = 0)) })
	private TraChannelMerchBindId id;
	/**
	 * 渠道商户
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "channel_merch_id", nullable = false, insertable = false, updatable = false)
	private TraChannelMerch channelMerch;
	/**
	 * 平台商户
	 */	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "merch_id", nullable = false, insertable = false, updatable = false)
	private Merch merch;
	/**
	 * 调用权重，值越大，概率越大
	 */
	@Column(name = "weight", nullable = false, precision = 8, scale = 0, columnDefinition="int(8) not null default '0'")
	private Integer weight;
	@PrePersist
	public void prePersist() {
		if (null == weight) {
			weight = 0;
		}
	}
	public TraChannelMerchBindId getId() {
		return id;
	}
	public void setId(TraChannelMerchBindId id) {
		this.id = id;
	}
	public TraChannelMerch getChannelMerch() {
		return channelMerch;
	}
	public void setChannelMerch(TraChannelMerch channelMerch) {
		this.channelMerch = channelMerch;
	}
	public Merch getMerch() {
		return merch;
	}
	public void setMerch(Merch merch) {
		this.merch = merch;
	}
	public Integer getWeight() {
		return weight;
	}
	public void setWeight(Integer weight) {
		this.weight = weight;
	}
	
}
